package com.jung.administrator.action;

import javax.annotation.Resource;

import com.jung.administrator.model.Administrator;
import com.jung.administrator.service.AdministratorService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class AdministratorAction extends ActionSupport{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
    
	private AdministratorService administratorService;
	@Resource
	public void setAdministratorService(AdministratorService administratorService) {
		this.administratorService = administratorService;
	}
    
	private String username;
	private String password;
	private String result;
	
	public void setUsername(String username) {
		this.username = username;
	}
	public String getUsername() {
		return username;
	}

	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}


	public String getResult() {
		return result;
	}


	public void setResult(String result) {
		this.result = result;
	}


	public String add(){
		Administrator administrator = new Administrator();
		administrator.setUsername(username);
		administrator.setPassword(password);
		administratorService.addAdministrator(administrator);
		return SUCCESS;
	}
	public String login(){
		if("match".equals(administratorService.login(username, password))){
			ActionContext.getContext().getSession().put("userLogin", username);
			this.result="success";
		}
		else{
			this.result="fail";
		}
		return SUCCESS;
	}
	private String newUserName;
	private String newPassword;
	
	public String getNewUserName() {
		return newUserName;
	}


	public void setNewUserName(String newUserName) {
		this.newUserName = newUserName;
	}


	public String getNewPassword() {
		return newPassword;
	}


	public void setNewPassword(String newPassword) {
		this.newPassword = newPassword;
	}

	public String updateAccount(){
		this.result=administratorService.updateAccount(username, password,newUserName,newPassword);
		return SUCCESS;
	}
	public String updateForward(){
		return SUCCESS;
	}
}
